<style type="text/css">
.button{background:url(images/left-menu-li.gif) repeat-x left top #F1F6F9; border:1px solid #318DAC; font-weight:bold; padding:2px 5px; font-weight:lighter; color:#318DAC; vertical-align:middle; -moz-border-radius:3px; -webkit-border-radius:3px; margin:auto 5px}
.center{text-align:center;}
.product_op{height:30px;}
.product_op span{cursor:pointer;}
.packageTips,.validateTips{color:red;line-height:25px;}
</style>

<style type="text/css">
div#add{
	text-align:center;
}
div.info{
	text-align:left;
}
div.item{
	margin-bottom: 12px;
}
input.text {
    height: 22px;    
    margin-left: 8px;
}
span.text{
	margin-left: 8px;
}
span.userInfoLeft{
	display:block;
	float:left;
	width:100px;
}
.hidden{display:none;}
#batchAddForm td,#batchAddForm th{border:1px solid #ccc;padding:3px;}
#batchAddForm .err td span{color:red}
</style>

<script type="text/javascript">
	$(function(){
		$("#list td").has("span").dblclick(function(){
			$(this).children("span").hide();
			$(this).children("input").removeClass("hidden").focus().blur(function(){			
				var val = $(this).val();
				$(this).siblings("span").text(val).show();
				$(this).addClass("hidden");
			});
		});
		
			
		// 弹出提示
		$("#alert_msg").dialog({
				autoOpen : false,
				modal : true,
				width : 600,
				show : "slide",
				buttons : {
					'返回列表' : function() {
						window.location.href = "/merchant/product/list";
					},
					'关闭' : function() {
						$(this).dialog('close');
					}
				}

			});
	});
	function del(obj){
		
		if(window.confirm("Are you confirm delete this record？")){
			$(obj).parent().parent().remove();		
		}
		return false;
	}
	
		
	function save() {
		vForm = '';
		vForm = $("#batchAddForm").serializeArray();		
		var tip = '';
		loading();
		$("#list tr").removeClass("err");
		$.ajax({
			type : "POST",
			async : false,
			dataType : "json",
			url : "/merchant/product/batch-add", // 请求的处理url
			data : vForm,
			success : function(json) {
				closeLoading();
				if (json.ask==0) {		
					var text = "";
					for(var tr_id in json.msg){
						$("#tr_"+tr_id).addClass("err");
						var err = "";
						for(var i in json.msg[tr_id]){
							err+=json.msg[tr_id][i];
						}
						text+=$("#tr_"+tr_id+" td:eq(0)").text()+": "+err+"<br/>";
					}		
					$('#alert_msg p').html(text);
					$('#alert_msg').dialog('open');
				}else{
					alert("Operating successful!");
					window.location.href="/merchant/product/list";
				}
			}
		});
	}
		
</script>
<div id="right_confirm" style="display: none;">
	<p style="text-align:center;font-size: 14px;color: red;font-weight: bold;">
	
	</p>
</div>

<div id="alert_msg" style="display: none;" title="提示信息">
	<p style="font-size: 14px;">
	
	</p>
</div>

<h3>Bulk add products
</h3>
<{if $err eq ""}>     
<form id="batchAddForm" name="batchAddForm">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="myTab">	
	<thead><tr>    	
    	<th>SKUNo</th>
    	<th>SKUName</th>
        <th>Category</th>        
        <th>Length</th>    
        <th>Height</th>    
        <th>Width</th>
        <th>Weight</th>
        <th>Declare Value</th>
        <th>Min Qty</th>
        
        <th>Action</th>
	</tr></thead>
    
	<tbody id="list">	
		<{foreach from=$products item=product key=key}>                    
		<tr class="" id="tr_<{$key}>">			
			<td>
				<span><{$product.SKUNo}></span>
				<input type="text" name="SKUNo[<{$key}>]" value="<{$product.SKUNo}>" class="hidden"/>
			</td>
			<td>
				<span><{$product.SKUName}></span>
				<input type="text" name="SKUName[<{$key}>]" value="<{$product.SKUName}>" class="hidden"/>
			</td>
			<td>
				<select name='Category[<{$key}>]' onchange='changeCategory(this);'>
					<{foreach from=$categorys item=option key=k}>
					<option value="<{$option.po_id}>_<{$option.poc_id}>" <{if $product.Category==$option.poc_value}>selected<{/if}>><{$option.poc_value}></option>
					<{/foreach}>
				</select>
			</td>
			<td>
				<span><{$product.product_length}></span>
				<input type="text" name="product_length[<{$key}>]" value="<{$product.product_length}>" class="hidden" size=5/>
			</td>
			<td>
				<span><{$product.product_width}></span>
				<input type="text" name="product_width[<{$key}>]" value="<{$product.product_width}>" class="hidden" size=5/>
			</td>
			<td>
				<span><{$product.product_height}></span>
				<input type="text" name="product_height[<{$key}>]" value="<{$product.product_height}>" class="hidden" size=5/>
			</td>
			<td>
				<span><{$product.product_weight}></span>
				<input type="text" name="product_weight[<{$key}>]" value="<{$product.product_weight}>" class="hidden" size=5/>
			</td>	
			<td>
				<span><{$product.product_declared_value}></span>
				<input type="text" name="product_declared_value[<{$key}>]" value="<{$product.product_declared_value}>" class="hidden" size=5/>
			</td>
			<td>
				<span><{$product.Min_Qty}></span>
				<input type="text" name="Min_Qty[<{$key}>]" value="<{$product.Min_Qty}>" class="hidden" size=5/>
			</td>		
			
			<td>
				<a title="delete" href="javascript:;" onclick="del(this);"><img
						src="/images/icon_del.gif" alt="delete"/></a>
			</td>
		</tr>
		<{/foreach}>
		

	</tbody>
	<tfooter>
		<tr class="">	
			
			<td colspan='11'>
				<input class="button" type="button" value=" Confirm  "   onclick="save()">&nbsp;&nbsp;
				<input class="button" type="button" value="  Back  "   onclick="history.go(-1);">&nbsp;&nbsp;
			</td>
			
		</tr>
	</tfooter>
	
</table>
</form>
<{else}>
<p style="font-size: 14px;color:red;font-weight:bold;text-align:center">
	<{$err}><a href="javascript:;" onclick="history.go(-1);" style="padding:0 0 0 20px;font-size:12px;color:#000;font-weight:normal;">Back</a>
</p>
<{/if}>


